package io.renren.modules.alarm.controller;

import io.renren.common.utils.R;
import io.renren.modules.alarm.entity.AlarmSensorVoEntity;
import io.renren.modules.alarm.service.AlarmSensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 传感器配置限值
 */
@RequestMapping("alarmSensor")
@RestController
public class AlarmSensorController {

    @Autowired
    private AlarmSensorService alarmSensorService;

    //获取设备集合以及设备下传感器集合
    @RequestMapping("getList")
    public R getList(@RequestParam Map<String, Object> params) {
        return R.ok(alarmSensorService.getList(params));
    }

    //根据设备id获取设备信息和设备下传感器集合
    @RequestMapping("get")
    public R get(Integer deviceId) {
        return alarmSensorService.get(deviceId);
    }

    //新增
    @RequestMapping("add")
    public R add(@RequestBody AlarmSensorVoEntity alarmSensorVo) {
        return alarmSensorService.add(alarmSensorVo);
    }

    //修改
    @RequestMapping("update")
    public R update(@RequestBody AlarmSensorVoEntity alarmSensorVo) {
        return alarmSensorService.update(alarmSensorVo);
    }

    //删除，参数为传感器id
    @RequestMapping("delete")
    public R delete(Integer id) {
        return alarmSensorService.delete(id);
    }

    /**
     * 删除，参数是设备id
     * 一并删除设备下所有传感器配置
     */
    @RequestMapping("deleteSensor")
    public R deleteSensor(Integer deviceId) {
        return alarmSensorService.deleteSensor(deviceId);
    }

}
